<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="../../lib/html5shiv.js?rev=@@hash"></script>
    <script type="text/javascript" src="../../lib/respond.min.js?rev=@@hash"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="../../static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="../../lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="../../lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="../../ht-css/style-q.css" />
    <title>权限管理</title>
</head>
<body>
<form action="" id="department_form">
    <div class="pd-30">
        <div class="row cl mb-20">
            <label class="form-label col-sm-2 text-r">部门名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="请输入部门名称" id="NAME" name="NAME"  onkeyup="ValidateValue(this)">
            </div>
        </div>

        <div class="text-c pd-20"><button class="btn btn-secondary radius" type="submit" id="subBtn">确定</button><a class="btn radius ml-10" onclick="dep_close()" href="javascript:void(0);">取消</a></div>
    </div>
</form>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="../../lib/jquery/1.9.1/jquery.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/layer/2.4/layer.js?rev=@@hash"></script>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="../../lib/My97DatePicker/4.8/WdatePicker.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/datatables/1.10.0/jquery.dataTables.min.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/laypage/1.2/laypage.js?rev=@@hash"></script>
<script src="../../ht-js/public.js?rev=@@hash"></script>
<!--验证token-->
<script src="../../ht-js/verifyToken.js?rev=@@hash"></script>
<script src="../../ht-js/access/organization.js?rev=@@hash"></script>
<!--表单验证-->
<script type="text/javascript" src="../../lib/jquery.validation/1.14.0/jquery.validate.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/jquery.validation/1.14.0/validate-methods.js?rev=@@hash"></script>
<script type="text/javascript" src="../../lib/jquery.validation/1.14.0/messages_zh.js?rev=@@hash"></script>
<script type="text/javascript">
    function ValidateValue(textbox) {
        var IllegalString = "[`~!#$^&*()=|{}':;',\\[\\].<>/?~！#￥……&*（）——|{}【】‘；：”“'。，、？]‘’";
        var textboxvalue = textbox.value;
        var index = textboxvalue.length - 1;
        var s = textbox.value.charAt(index);
        if (IllegalString.indexOf(s) >= 0) {
            s = textboxvalue.substring(0, index);
            textbox.value = s;
        }
    }
    var editData = JSON.parse(window.session_storage.getItem('department_editData'));
    function dep_close(){
        var index =  parent.location.reload();
        parent.layer.close(index);
    }
    /* 验证保存父部门*/
    $(function() {
        var editData = JSON.parse(window.session_storage.getItem('department_editData'));
        if (editData.DEPARTMENT_ISEIDT == 'depParentAdd'){
            $("#department_form").validate({
                rules: {
                    NAME: {
                        required: true,
                        minlength: 1,
                        maxlength: 20
                    },
                },
                onkeyup: false,
                focusCleanup: true,
                success: "valid",
                submitHandler: function (form) {
                    $.ajax({
                        type: "POST",
                        url: root.accessInter.access_department_saveApi,
                        data: {
                            DEPARTMENT_NAME:$("#NAME").val(),
                            DEPARTMENT_ID:editData.DEPARTMENT_ID
                        },
                        dataType:'json',
                        cache: false,
                        success: function (data) {
                            switch (data.code) {
                                case 200:
                                    layer.msg(data.data.errors[0], {icon: 1, time: 1000});
                                    var index =  parent.location.reload();
                                    break;
                                case 400:
                                    layer.msg(data.data.errors[0], {icon: 1, time: 1000});
                                    break;
                                case 404:
                                    layer.msg(data.data.errors[0], {icon: 1, time: 1000});
                                    break;
                                case 403:
                                    layer.msg(data.data.errors[0], {icon: 1, time: 1000});
                                    break;
                            }
                        },
                        error: function (XmlHttpRequest, textStatus, errorThrown) {
                            layer.msg('error!', {icon: 1, time: 2000});
                        }
                    });

                }
            });
        }else if(editData.DEPARTMENT_ISEIDT == 'depParentEidt'){
            var editData = JSON.parse(window.session_storage.getItem('delDep'));
            $("#NAME").val(editData.DEPARTMENT_NAME);
            $("#department_form").validate({
                rules: {
                    NAME: {
                        required: true,
                        minlength: 1,
                        maxlength: 20
                    },
                },
                onkeyup: false,
                focusCleanup: true,
                success: "valid",
                submitHandler: function (form) {
                    $.ajax({
                        type: "POST",
                        url: root.accessInter.access_department_editApi,
                        data: {
                            DEPARTMENT_NAME:$("#NAME").val(),
                            DEPARTMENT_ID:editData.DEPARTMENT_ID,
                            //我添加的
                            PARENT_ID:editData.PARENT_ID
                        },
                        dataType:'json',
                        cache: false,
                        success: function (data) {
                            console.log(data.code);
                            switch (data.code) {
                                case 200:
                                    layer.msg(data.data.errors[0], {icon: 1, time: 1000});
                                    var index =  parent.location.reload();
                                    break;
                                case 404:
                                    layer.msg(data.data.errors[0], {icon: 1, time: 1000});
                                    break;
                                case 400:
                                    layer.msg(data.data.errors[0], {icon: 1, time: 1000});
                                    break;
                            }
                        },
                        error: function (XmlHttpRequest, textStatus, errorThrown) {
                            layer.msg('error!', {icon: 1, time: 2000});
                        }
                    });
                }
            });
        }else if(editData.DEPARTMENT_ISEIDT == 'depChildAdd'){
            var editData = JSON.parse(window.session_storage.getItem('delDep'));
            $("#department_form").validate({
                rules: {
                    NAME: {
                        required: true,
                        minlength: 1,
                        maxlength: 20
                    },
                },
                onkeyup: false,
                focusCleanup: true,
                success: "valid",
                submitHandler: function (form) {
                    $.ajax({
                        type: "POST",
                        url: root.accessInter.access_department_saveNextApi,
                        data: {
                            DEPARTMENT_NAME:$("#NAME").val(),
                            DEPARTMENT_ID:editData.DEPARTMENT_ID,
                            PARENT_ID:editData.DEPARTMENT_ID,
                            P_BIANMA:editData.P_BIANMA,
                            MAX_NUM:editData.MAX_NUM
                        },
                        dataType:'json',
                        cache: false,
                        success: function (data) {
                            switch (data.code) {
                                case 200:
                                    layer.msg(data.data.errors[0], {icon: 1, time: 1000});
                                    var index =  parent.location.reload();
                                    break;
                                case 400:
                                    layer.msg(data.data.errors[0], {icon: 1, time: 1000});
                                    break;
                                case 404:
                                    layer.msg(data.data.errors[0], {icon: 1, time: 1000});
                                    break;
                            }
                        },
                        error: function (XmlHttpRequest, textStatus, errorThrown) {
                            layer.msg('error!', {icon: 1, time: 2000});
                        }
                    });
                }
            });
        }
    })

</script>
</body>
</html>